package com.we823.project.controller.repo;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.project.controller.AbstractBaseController;
import com.we823.project.core.web.WebConstants;
import com.we823.project.model.repo.MaterialStockReturnModel;
import com.we823.project.repository.service.repo.MaterialStockReturnService;

@Controller
@RequestMapping(WebConstants.REPO_STOCK+"/return")
public class MaterialStockReturnController extends AbstractBaseController<MaterialStockReturnModel> {

	private String baseUrl = WebConstants.REPO_STOCK_TEMPLATE + "return/";
	
	private MaterialStockReturnService materialStockReturnService;
	
	@Autowired
	public MaterialStockReturnController(MaterialStockReturnService materialStockReturnService) {
		super(materialStockReturnService);
		this.materialStockReturnService=materialStockReturnService;
		super.baseUrl=baseUrl;
		setResourceIdentity("repo:stock_return");
	}

	@Override
	public Page<MaterialStockReturnModel> getData(PageRequest pageRequest,
			HttpServletRequest request, Model model, boolean pageable) {
		Page<MaterialStockReturnModel> mPage = null;
		if(pageable) {
			mPage = materialStockReturnService.findAll(pageRequest);
		}else {
			mPage = new PageImpl<>(materialStockReturnService.findAll());
		}
		return mPage;
	}

}
